#1.Prelims ----
library(ggplot2)
library(ggmap)
library(usmap)
library(mapdata)
library(ggthemes)
library(dplyr)
library(RColorBrewer)
library(viridis)
library(maps)
library(cowplot) # for plot_grid() function - good to arrange multiple plots into a grid
library(grid)
library(gridGraphics)
library(patchwork)
library(gridExtra)
library(colorspace)


library(ggpubr)
require(maps)
require(viridis)

theme_set(
  theme_void()
)

theme_set(theme_classic())

#2.Paths ----


BASEPATH="C://Users//wb520443//Dropbox//Research Projects//Global pollution//2_analysis//Replication"


#3.Data ----
#Pollution data
pm_urca<-read.csv(paste0(BASEPATH,"/figdat/urca_rwi.csv"), header = TRUE)


urca_rwi<-ggplot(pm_urca, aes(urca,rwi)) +
  geom_raster(aes(fill = count), interpolate = TRUE)+
  geom_line(data=pm_urca, aes(x=urca, y=urca1,z=NULL), 
            size=1 ,linetype='dashed', col='grey50')+
  geom_line(data=pm_urca, aes(x=urca, y=urca2,z=NULL), 
            size=1,linetype='dashed' , col='grey50')+
  geom_line(data=pm_urca, aes(x=urca, y=urca3,z=NULL), 
            size=1,linetype='dashed' , col='grey50')+
  geom_segment(x=7.2, xend=7.2,y=-1.7, yend=102,linetype='dotted')+
  geom_segment(x=14.7, xend=14.7,y=-1.7, yend=102,linetype='dotted')+
  annotate(geom = "text", x = c(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30), y = -2, 
           label = c(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30), size = 3) +
  scale_fill_continuous_sequential(palette = 'Blues 2', 
                                   na.value = "grey100",
                                   c1 = 80, c2 = 10, p1 = 1.8,
                                   guide = "none")+
  theme(legend.direction="horizontal", legend.position="bottom",
        legend.margin=margin(-18, 0, 0, 0))+
  theme(text = element_text(size = 20))+ 
  theme(legend.background=element_blank())+
  theme(axis.line.x = element_blank(),
        axis.line.y = element_blank())+
  xlab(element_blank())+
  ylab(element_blank())+
  labs(subtitle = "") +
  theme(plot.subtitle = element_text(size = 30,  hjust = 0.02)) +
  scale_x_continuous(breaks=c(3.5,10.5,22),labels = paste0(c("Urban", "Peri-Urban", "Rural")))+
  scale_y_continuous(breaks=c(-1.5, 0, 1.5))





ggsave(filename = paste0(BASEPATH,"//figures//urca_rwi_raster.pdf"), 
       plot = urca_rwi,        width = 7,
       height = 4,
       units = c("in"),
       dpi = 300)



